package top.tangyh.lamp.care.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.tangyh.basic.base.R;
import top.tangyh.basic.interfaces.echo.EchoService;
import top.tangyh.basic.base.controller.SuperController;
import top.tangyh.lamp.care.service.BIoRecordService;
import top.tangyh.lamp.care.entity.BIoRecord;
import top.tangyh.lamp.care.vo.query.*;
import top.tangyh.lamp.care.vo.result.*;
import top.tangyh.lamp.care.vo.save.BIoRecordSaveVO;
import top.tangyh.lamp.care.vo.save.IoRecordInVO;
import top.tangyh.lamp.care.vo.save.IoSuspensionFrameDataInVo;
import top.tangyh.lamp.care.vo.update.BIoRecordUpdateVO;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * 出入量记录表
 * </p>
 *
 * @author zqb
 * @date 2024-07-23 10:12:06
 * @create [2024-07-23 10:12:06] [zqb] [代码生成器生成]
 */
@Slf4j
@RequiredArgsConstructor
@Validated
@RestController
@RequestMapping("/oivolume")
@Tag(name = "出入量")
public class BIoRecordController {
//    extends SuperController<BIoRecordService, Long, BIoRecord
//            , BIoRecordSaveVO, BIoRecordUpdateVO, BIoRecordPageQuery, BIoRecordResultVO>
//    private final EchoService echoService;
//    @Override
//    public EchoService getEchoService() {
//        return echoService;
//    }


    private final BIoRecordService bIoRecordService;

    /**
     * 出入量记录 添加/修改值
     */
    @PostMapping("/addOrUpdateYxIoRecord")
    @Operation(summary = "增加/修改出入量")
    public R<Long> addOrUpdateYxIoRecord(@RequestBody IoRecordInVO yxIoRecordPO) {
        return R.success(bIoRecordService.addOrUpdateYxIoRecord(yxIoRecordPO));
    }

    @PostMapping("/addOrUpdateYxIoRecord/batch")
    @Operation(summary = "批量增加/修改出入量")
    public R<Object> addOrUpdateYxIoRecordBatch(@RequestBody List<IoRecordInVO> yxIoRecordPOs) {
        return R.success(bIoRecordService.addOrUpdateYxIoRecordBatch(yxIoRecordPOs));
    }

    /**
     * 查询出入量
     */
    @PostMapping(value = "/list")
    @Operation(summary =  "查询出量和入量")
    public R<Map<String, Map<String, List<IoRecordVO>>>> statisticInAndOutSum(@RequestBody SelectStatisticParam param) {
        return R.success(bIoRecordService.listOfIoRecord(param));
    }

    @GetMapping("/item/query")
    @Operation(summary = "查询病人出入量选项")
    public R<List<IoItemVO>> list(@Valid IoItemQueryParam ioItemQueryParam) {
        return R.success(bIoRecordService.itemQuery(ioItemQueryParam));
    }

    /**
     * 查询出量和入量指定时间的统计
     */
    @PostMapping(value = "/statistics")
    @Operation(summary =  "查询出量和入量指定时间的统计")
    public R<SumOfIoStatisticslVO> statisticInAndOutSum(@RequestBody SelectStatisticIOSumParam param) {
        return R.success(bIoRecordService.selectSumStatistic(param.getHospitalNumber(), param.getStartTime(), param.getEndTime()));
    }

    @DeleteMapping
    @Operation(summary = "根据出入量时间删除")
    public R<Integer> delete(@RequestParam @Parameter(name = "time", description = "出入量时间 例：2021-12-29 01:00:00", required = true) String time) {
        return R.success(bIoRecordService.deleteByTime(time));
    }

    @DeleteMapping("/delete/{id}")
    @Operation(summary = "根据出入量id删除")
    public R<Boolean> deleteById(@PathVariable Long id) {
        List<Long > ids=new ArrayList<>();
        ids.add(id);
        return R.success(bIoRecordService.removeByIds(ids));
    }

    @Operation(summary = "出入量悬浮框数据")
    @PostMapping("/suspension/frame/data")
    public R<List<IoSuspensionFrameData>> selectIoSuspensionFrameData(@RequestBody @Valid IoSuspensionFrameDataInVo queryVO) {

        return R.success(bIoRecordService.selectIoSuspensionFrameData(queryVO));
    }

    @Operation(summary = "出入量弹框列表")
    @PostMapping("/dialog/list")
    public R<List<DataForIoOUtVO>> selectDialogList(@RequestBody @Valid DataForIoVOQuery queryVO) {
        List<DataForIoOUtVO> result = bIoRecordService.selectDialogList(queryVO);
        return R.success(result);
    }


}


